<template>
  <div class="user-index">
    <div class="user-info">
      <div class="user-avatar">
        <img src="../../assets/home/uy-1.png" alt="" />
      </div>
      <div class="user-name">
        <div class="u-1">{{ store.user?.user.nickName }}</div>
        <div class="u-2">
          {{ xename }}已陪您{{ store.user?.user.regDays }}天了
        </div>
      </div>
    </div>
    <div class="user-menu">
      <div class="menu-1">
        <CpRadioBtn title="最近使用" @cadd="zjadd"></CpRadioBtn>
        <div class="icon-1">
          <div
            class="home-1-co4"
            v-for="(item, index) in arr"
            :key="index"
            @click="zjadds(item)"
          >
            <img :src="item.iconUrl" class="imgs-1" />
            <div class="home-1-co5">{{ item.appName }}</div>
          </div>
        </div>
      </div>
      <!-- 学习记录 -->
      <div class="xue-1">
        <CpRadioBtn title="学习记录" @cadd="xjadd"></CpRadioBtn>
        <record></record>
      </div>
      <div class="ying-1">
        <van-cell
          :title="item.label"
          is-link
          :to="item.path"
          :border="false"
          v-for="(item, index) in tools"
          :key="index"
        >
          <template #icon><cp-icon :name="`user-ic${index + 1}`" /></template>
        </van-cell>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import record from './components/record.vue'
import { useUserStore, useListStore } from '@/stores'
import { useRouter } from 'vue-router'
import { ref, onMounted } from 'vue'
import { getRecent } from '@/utils/Commonmethod'

const store = useUserStore()
const router = useRouter()
const xename: any = ref('学在农林')
const setList = useListStore()
const arr: any = ref([])
const tools = [
  {
    label: '访问记录',
    path: '/AppList'
  },
  {
    label: '操作指南',
    path: '/Picture'
  },
  {
    label: '咨询记录',
    path: '/Feedback'
  }
]
const zjadd = () => {
  router.push('/notify')
}
const xjadd = () => {
  router.push('/article')
}
const zjadds = (item: any) => {
  window.open(item.appUrl)
}
onMounted(async () => {
  xename.value = setList.sysinfo.sysName
  arr.value = await getRecent({ pageNum: 1, pageSize: 4 })
})
</script>

<style lang="scss" scoped>
.user-index {
  padding-bottom: 57px;
  width: 100%;
  height: 100%;
  background: #f7f7f7;
  box-sizing: border-box;
}
.user-info {
  width: 100%;
  height: 120px;
  background-image: url('../../assets/user/bg.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  padding: 18px;
  display: flex;
  align-items: center;
  box-sizing: border-box;
}
.user-avatar {
  width: 50px;
  height: 50px;
  img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 1px solid #fff;
  }
}
.user-name {
  margin-left: 18px;
}
.u-1 {
  font-weight: 500;
  font-size: 19px;
  color: #333333;
  margin-bottom: 4px;
}
.u-2 {
  font-weight: 400;
  font-size: 15px;
  color: #777777;
}
.user-menu {
  width: 100%;
  padding: 0 11px;
  box-sizing: border-box;
}
.menu-1 {
  width: 100%;
  height: 130px;
  background: #ffffff;
  border-radius: 8px;
  border: 1px solid #e5e5e5;
  padding: 11px;
  box-sizing: border-box;
}

.img-1 {
  width: 22px;
  height: 22px;
  margin-top: -3px;
}
.icon-1 {
  width: 100%;
  height: 70px;
  display: flex;
}
.home-1-co4 {
  width: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.home-1-co5 {
  width: 100%;
  text-align: center;
  font-weight: 400;
  font-size: 13px;
  color: #333333;
}
.imgs-1 {
  width: 40px;
  height: 40px;
}
.xue-1 {
  width: 100%;
  height: 202px;
  background: #ffffff;
  border-radius: 8px;
  margin-top: 11px;
  border: 1px solid #e5e5e5;
  padding: 11px;
  box-sizing: border-box;
}
.ying-1 {
  width: 100%;
  height: 160px;
  background: #ffffff;
  border-radius: 8px;
  margin-top: 21px;
}
.van-cell {
  align-items: center;
}
.cp-icon {
  font-size: 17px;
  margin-right: 10px;
}
</style>
